/**
 * selectCount  总数查询
 * selectLimit  分页查询
 * selectCountLike 模糊查询总数
 * selectLikeLimit  分页模糊查询
 * idSelect     根据id获取公告信息
 * insert 添加公告
 * idUpdate     根据Id修改公告信息
 * delete       根据id删除公告
 */

const util = require("../util")
const table = "announcement"
const str = "title, content, scope, ctime, job_number"
const scope = {
  4: "",
  3: "",
  2: " and (scope = 2 or scope = 3)",
  1: " and (scope = 1 or scope = 3)",
}
const like = " and title"

exports.select = (data) => util.select(str, table, util.selectTransition(data))

exports.selectCount = (data, type) =>
  util.selectCount(table, util.selectTransition(data) + (type ? scope[type] : ''))

exports.selectLimit = (data, page, pagesize, type) =>
  util.selectLimit(
    str,
    table,
    util.selectTransition(data) + scope[type],
    page,
    pagesize,
    'id desc'
  )

exports.selectCountLike = (d, type) =>
  util.selectCountLike(table, scope[type] + like, d)

exports.selectLikeLimit = (d, page, pagesize, type) =>
  util.selectLikeLimit(str, table, scope[type] + like, d, page, pagesize, true)

exports.idSelect = (id) => util.idSelect(str, table, id)

exports.insert = (data) =>
  util.insert(table, util.insertStr(data), util.insertTransition(data))

exports.idUpdate = (data, id) =>
  util.idUpdate(table, util.updateTransition(data), id)

exports.delete = (id) => util.delete(table, id)
